package com.appspot.moviesessions;

import android.content.ContentResolver;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
import android.view.View;
import android.widget.TextView;

public class ViewBinderFactoryImpl implements ViewBinderFactory {

	private ContentResolver contentResolver;
	private UriParser uriParser;
	private BitmapFactory bitmapFactory;

	public ViewBinderFactoryImpl(ContentResolver contentResolver,
			UriParser uriParser, BitmapFactory bitmapFactory) {
		this.contentResolver = contentResolver;
		this.uriParser = uriParser;
		this.bitmapFactory = bitmapFactory;
	}

	@Override
	public ViewBinder movieListViewBinder() {
		return new MovieListViewBinder(contentResolver, uriParser,
				bitmapFactory);
	}

	@Override
	public ViewBinder movieInfoViewBinder() {
		return new MovieInfoViewBinder();
	}

	@Override
	public ViewBinder movieSpinnerViewBinder() {
		return new ViewBinder() {

			@Override
			public boolean setViewValue(View arg0, Cursor cursor, int colIndex) {
				TextView view = (TextView) arg0;
				view.setText(cursor.getString(colIndex));
				return true;
			}
		};
	}

	@Override
	public ViewBinder locationSpinnerViewBinder() {

		return movieSpinnerViewBinder();
	}
}
